<?php
/**
 * Created by 784855684@qq.com.
 * Link: https://github.com/lichtung/wshore
 * User: linzh
 * Date: 7/11/17
 * Time: 9:07 AM
 */
declare(strict_types=1);


namespace application\module\admin\model;


use wshore\core\ActiveRecord;

/**
 * Class NotificationModel
 *
 * @property string $sender 接收者
 * @property string $receiver
 * @property string $content 消息内容
 * @property string $addtime
 * @property string $title 标题
 * @property int $looked 消息查看时间戳,未查看为0
 *
 * @package application\module\admin\model
 */
class NotificationModel extends ActiveRecord
{
    protected function tablePrefix()
    {
        return 'ws_';
    }

    protected function tableName()
    {
        return 'notification';
    }

    public $user_email = '';


    public function __construct($id = null)
    {
        if ($id) {
            if (is_numeric($id)) {
                parent::__construct($id);
            } else {
                parent::__construct();
                $this->user_email = $id;
            }
        } else {
            parent::__construct();
        }
    }

    public function getUnlookedNotificationList()
    {
        $list = $this->where(['receiver' => $this->user_email, 'looked' => 0])->select();
        return $list;
    }

    public function createStatement()
    {
        return 'CREATE TABLE `naz_notification` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `sender` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `receiver` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT \'接收者\',
  `content` varchar(2550) COLLATE utf8_unicode_ci NOT NULL COMMENT \'消息内容\',
  `addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `looked` int(3) unsigned NOT NULL DEFAULT \'0\' COMMENT \'消息查看时间戳,未查看为0\',
  `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT \'\' COMMENT \'标题\',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
';
    }

}